<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<html lang="zh-CN">
<head>
    <meta charset="GB18030">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta name="description" content="">
    <meta name="author" content="">
    <link rel="stylesheet" href="${pageContext.request.contextPath}/resources/bootstrap/css/bootstrap.min.css">
    <link rel="stylesheet" href="${pageContext.request.contextPath}/resources/css/font-awesome.min.css">
    <link rel="stylesheet" href="${pageContext.request.contextPath}/resources/css/main.css">
    <link rel="stylesheet" href="${pageContext.request.contextPath}/resources/css/carousel.css">
    <style>
        .tree li {
            list-style-type: none;
            cursor: pointer;
        }

        table tbody tr:nth-child(odd) {
            background: #F4F4F4;
        }

        table tbody td:nth-child(even) {
            color: #C00;
        }

        th {
            text-align: center
        }
    </style>
</head>
<body>
<div class="navbar-wrapper ">
    <%--动态导入另一个jsp页面，作用：将公共使用的部分提取出来，然后使用动态导入
              动态导入是不会导入include页面的编译指令的，而是仅仅将被导入页面的body内容插入本页面。--%>
    <jsp:include page="admin-header.jsp"></jsp:include>
</div>
<div class="container-fluid">
    <div class="row">
        <%--动态导入另一个jsp页面，作用：将公共使用的部分提取出来，然后使用动态导入
                     动态导入是不会导入include页面的编译指令的，而是仅仅将被导入页面的body内容插入本页面。--%>
        <jsp:include page="admin-left.jsp"></jsp:include>
        <div class="col-sm-9 col-sm-offset-3 col-md-10 col-md-offset-2 main">
            <div class="panel panel-default">
                <div class="panel-heading">
                    <h3 class="panel-title"><i class="glyphicon glyphicon-th"></i> 数据列表</h3>
                </div>
                <div class="panel-body">
                    <form class="form-inline" action="${pageContext.request.contextPath}/tbUser/fuzzy" method="post"
                          role="form" style="float:left;">
                        <div class="form-group has-feedback">
                            <div class="input-group">
                                <div class="input-group-addon">查询条件</div>
                                <input class="form-control has-success" type="text" placeholder="请输入查询条件"
                                       name="fuzzy">
                            </div>
                        </div>
                        <button type="submit" class="btn btn-warning"><i class="glyphicon glyphicon-search"></i> 查询
                        </button>
                        <button type="button" class="btn btn-success" onclick="location.replace('/adduser-page')"><i
                            class="glyphicon glyphicon-plus"></i> 新增报修人
                        </button>
                    </form>
                    <br>
                    <hr style="clear:both;">
                    <div class="table-responsive">
                        <table class="table table-responsive table-hover" align="center">
                            <thead>
                            <tr>
                                <th>序号</th>
                                <th>账户</th>
                                <th>真实姓名</th>
                                <th>用户电话</th>
                                <th>用户邮箱</th>
                                <th>注册时间</th>
                                <th>注销状态</th>
                                <th>审核状态</th>
                                <th>注销</th>
                                <th>审核</th>

                            </tr>
                            </thead>
                            <tbody align="center" id="idList">
                            <c:forEach var="userInfo" items="${userInfos.list}">
                                <tr>
                                    <td>${userInfo.userId}</td>
                                    <td><span data-toggle="tooltip" title="登录账号">${userInfo.userAccount}</span></td>
                                    <td><span data-toggle="tooltip" title="用户名">${userInfo.username}</span></td>
                                    <td><span data-toggle="tooltip" title="联系电话">${userInfo.userTel}</span></td>
                                    <td><span data-toggle="tooltip" title="邮箱地址">${userInfo.userEmail}</span></td>
                                    <td><span data-toggle="tooltip" title="添加时间">
                                        <fmt:formatDate value="${userInfo.createTime}" pattern="yyyy-MM-dd"/></span>
                                    </td>
                                    <td>
                                        <c:if test="${userInfo.isDeleted==false}">
                                            <button type="button" class="btn btn-success btn-xs"
                                                    data-toggle="tooltip"
                                                    title="账户可用">正 &nbsp; 常
                                            </button>
                                        </c:if>
                                        <c:if test="${userInfo.isDeleted==true}">
                                            <button type="button" class="btn btn-warning btn-xs"
                                                    data-toggle="tooltip"
                                                    title="账户不可用">已注销
                                            </button>
                                        </c:if>

                                    </td>
                                    <td>
                                        <c:if test="${userInfo.userLocked==false}">
                                            <button type="button" class="btn btn-success btn-xs"
                                                    data-toggle="tooltip"
                                                    title="账号可登陆">已审核
                                            </button>
                                        </c:if>
                                        <c:if test="${userInfo.userLocked==true}">
                                            <button type="button" class="btn btn-warning btn-xs"
                                                    data-toggle="tooltip"
                                                    title="账号不可登陆">未审核
                                            </button>
                                        </c:if>

                                    </td>
                                    <c:if test="${userInfo.isDeleted==true}">
                                        <td>
                                            <button type="button" class="btn btn-info btn-xs" data-toggle="tooltip"
                                                    title="激活账户" onclick="jihuoOk(${userInfo.userId},this)"><i
                                                class=" glyphicon glyphicon-check"></i>
                                            </button>
                                        </td>
                                    </c:if>
                                    <c:if test="${userInfo.isDeleted==false}">
                                        <td>
                                            <button type="button" class="btn btn-danger btn-xs"
                                                    data-toggle="tooltip"
                                                    title="确认注销" onclick="jihuoNo(${userInfo.userId},this)"><i
                                                class=" glyphicon glyphicon-remove"></i>
                                            </button>
                                        </td>
                                    </c:if>
                                    <c:if test="${userInfo.userLocked==true}">
                                        <td>
                                            <button type="button" class="btn btn-info btn-xs" data-toggle="tooltip"
                                                    title="通过审核" onclick="shenheOk(${userInfo.userId},this)"><i
                                                class=" glyphicon glyphicon-check"></i>
                                            </button>
                                        </td>
                                    </c:if>
                                    <c:if test="${userInfo.userLocked==false}">
                                        <td>
                                            <button type="button" class="btn btn-danger btn-xs"
                                                    data-toggle="tooltip"
                                                    title="不通过审核" onclick="shenheNo(${userInfo.userId},this)"><i
                                                class=" glyphicon glyphicon-remove"></i>
                                            </button>
                                        </td>
                                    </c:if>
                                </tr>
                            </c:forEach>
                            </tbody>
                            <tfoot>
                            <tr>
                                <td colspan="10" align="right">
                                    当前${userInfos.pageNum }页,总${userInfos.pages }页,总${userInfos.total }条记录
                                </td>
                            </tr>
                            <tr>
                                <td colspan="10" align="center">
                                    <ul class="pagination">
                                        <li><a
                                            href="${pageContext.request.contextPath}/tbUser/searchUser?page=1">首页</a>
                                        </li>
                                        <!-- 判断是否有上一页，以便显示点击按钮 -->
                                        <c:if test="${userInfos.hasPreviousPage }">
                                            <li>
                                                <a href="${pageContext.request.contextPath}/tbUser/searchUser?page=${userInfos.pageNum-1 }"
                                                   aria-label="Previous">
                                                    <span aria-hidden="true">&laquo;</span>
                                                </a>
                                            </li>
                                        </c:if>
                                        <!-- 遍历页码 -->
                                        <c:forEach items="${userInfos.navigatepageNums }" var="page_Num">
                                            <c:if test="${page_Num == userInfos.pageNum }">
                                                <li class="active"><a href="#">${page_Num }</a></li>
                                            </c:if>
                                            <c:if test="${page_Num != userInfos.pageNum }">
                                                <li><a
                                                    href="${pageContext.request.contextPath}/tbUser/searchUser?page=${page_Num }">${page_Num}</a>
                                                </li>
                                            </c:if>
                                        </c:forEach>
                                        <!-- 判断是否有下一页 -->
                                        <c:if test="${userInfos.hasNextPage }">
                                            <li>
                                                <a href="${pageContext.request.contextPath}/tbUser/searchUser?page=${userInfos.pageNum+1 }"
                                                   aria-label="Next">
                                                    <span aria-hidden="true">&raquo;</span>
                                                </a>
                                            </li>
                                        </c:if>

                                        <li><a
                                            href="${pageContext.request.contextPath}/tbUser/searchUser?page=${userInfos.pages }">末页</a>
                                        </li>
                                    </ul>

                                </td>
                            </tr>
                            </tfoot>
                        </table>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

<script src="${pageContext.request.contextPath}/resources/jquery/jquery-2.1.1.min.js"></script>
<script src="${pageContext.request.contextPath}/resources/bootstrap/js/bootstrap.min.js"></script>
<script src="${pageContext.request.contextPath}/resources/script/docs.min.js"></script>
<script type="text/javascript">

    $(function () {

        $("[data-toggle='tooltip']").tooltip();

        $(".list-group-item").click(function () {
            if ($(this).find("ul")) {
                $(this).toggleClass("tree-closed");
                if ($(this).hasClass("tree-closed")) {
                    $("ul", this).hide("fast");
                } else {
                    $("ul", this).show("fast");
                }
            }
        });
    });

    /*激活账户操作*/
    function jihuoOk(userId, obj) {
        //alert("账户id====" + userId)
        if (confirm("请确认操作")) {
            $.ajax({
                url: '/tbUser/updateStatus',

                data: {
                    userId: userId,
                    isDeleted: 0  //表示已激活
                },
                type: 'POST',
                dataType: 'json',
                success: function (data) {
                    if (data.flag) {
                        alert(data.msg);
                        location.reload();
                    } else {
                        alert(data.msg);
                    }
                }
            });
        } else {
            location.reload()
        }
    };

    /*确认注销操作*/
    function jihuoNo(userId, obj) {
        //alert("账户id====" + userId)
        if (confirm("请确认操作")) {
            $.ajax({
                url: '/tbUser/updateStatus',

                data: {
                    userId: userId,
                    isDeleted: 1  //1表示已注销
                },
                type: 'POST',
                dataType: 'json',
                success: function (data) {
                    if (data.flag) {
                        alert(data.msg);
                        //location.replace('/tbUser/searchUser')
                        location.reload()
                    } else {
                        alert(data.msg);
                    }
                }
            });
        } else {
            location.reload()
        }
    };

    /*审核账户操作*/
    function shenheOk(userId, obj) {
        //alert("账户id====" + userId)
        if (confirm("请确认操作")) {
            $.ajax({
                url: '/tbUser/updateStatus',

                data: {
                    userId: userId,
                    userLocked: 0  //表示已激活
                },
                type: 'POST',
                dataType: 'json',
                success: function (data) {
                    if (data.flag) {
                        alert(data.msg);
                        //location.replace('/tbUser/searchUser')
                        location.reload()
                    } else {
                        alert(data.msg);
                    }
                }
            });
        } else {
            location.reload()
        }
    };

    /*不通过审核操作*/
    function shenheNo(userId, obj) {
        //alert("账户id====" + userId)
        if (confirm("请确认操作")) {
            $.ajax({
                url: '/tbUser/updateStatus',

                data: {
                    userId: userId,
                    userLocked: 1  //1表示已注销
                },
                type: 'POST',
                dataType: 'json',
                success: function (data) {
                    if (data.flag) {
                        alert(data.msg);
                        //location.replace('/tbUser/searchUser')
                        location.reload()
                    } else {
                        alert(data.msg);
                    }
                }
            });
        } else {
            location.reload()
        }
    };
</script>
</body>
</html>
